<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>批量设置</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
  <style>
    .layui-form-radio {
      padding-right: unset;
    }
  </style>
</head>
<body>


<div class="layui-form" lay-filter="layuiadmin-form-role" id="layuiadmin-form-role" style="padding: 20px 30px 0 0;">

  <div class="layui-form-item">
    <label class="layui-form-label">代理商</label>
    <div class="layui-input-block">
      <select name="agent_id" lay-verify="required" lay-search>
        <option value="">请选择</option>
        <option value="0">分销平台</option>
        {foreach $agents as $k => $v}
        <option value="{$v.id}">{$v.account}【{$v.remarks}】</option>
        {/foreach}
      </select>
    </div>
  </div>


  {foreach $template as $k => $v}
  <input name="default[{$k}]" type="hidden" id="input_{$k}" value="0">
  <div class="layui-form-item defult recommend" id="item_{$k}" style="display: none;">
    <label class="layui-form-label"></label>
    <div class="layui-input-inline" style="width: 150px !important;">
      <input type="text" name="title[{$k}]" lay-verify="required|title" placeholder="请输入推荐位标题" autocomplete="off" class="layui-input" value="{$v.title}">
    </div>

    <div class="layui-input-inline" style="width: 250px !important;">
      <input type="radio" name="freq[{$k}]"  value="0" title="无区分" {if $v.freq == 0}checked{/if}>
      <input type="radio" name="freq[{$k}]"  value="1" title="男频" {if $v.freq == 1}checked{/if}>
      <input type="radio" name="freq[{$k}]"  value="2" title="女频" {if $v.freq == 2}checked{/if}>
    </div>


    <div class="layui-btn-group">
      <button type="button" class="layui-btn layui-btn-primary layui-btn-xs" style="margin-top: 8px;" onclick="delItem('{$k}');">
        <i class="layui-icon">&#xe640;</i>
      </button>
    </div>
  </div>
  {/foreach}

  <div class="layui-form-item" id="addButton">
    <label class="layui-form-label"></label>
    <div class="layui-input-inline" style="width: unset;">
      <div class="layui-btn-group">
        <button type="button" class="layui-btn"  onclick="addItem();">添加推荐位</button>
      </div>
    </div>
    <div class="layui-form-mid layui-word-aux"><a href="javascript:;" style="color: #01AAED;" onclick="showDefult();">获取默认推荐位模板</a></div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label"></label>
    <div class="layui-input-block">
      <ul class="layui-timeline">
        <li class="layui-timeline-item">
          <i class="layui-icon layui-timeline-axis"></i>
          <div class="layui-timeline-content layui-text">
            <h3 class="layui-timeline-title">第一步</h3>
            <p>
              查看UI设计的App页面，定义相应推荐位，如：<i lay-tips="<img src='/static/imgs/tuijianwei.jpg' width='200'>" class="layui-icon layui-icon-about"></i>选择男频，如果页面的推荐位没有区分频道，如：<i class="layui-icon layui-icon-about"  lay-tips="<img src='/static/imgs/sousuo.jpg' width='200'>"></i>就选无区分
            </p>
          </div>
        </li>
        <!--<li class="layui-timeline-item">
          <i class="layui-icon layui-timeline-axis"></i>
          <div class="layui-timeline-content layui-text">
            <h3 class="layui-timeline-title">第二步</h3>
            <p>
              导出相应App的推荐位给前端，让前端使用相应location_key获取推荐位
            </p>
          </div>
        </li>-->
        <li class="layui-timeline-item">
          <i class="layui-icon layui-timeline-axis"></i>
          <div class="layui-timeline-content layui-text">
            <h3 class="layui-timeline-title">第二步</h3>
            <p>
              设置推荐位相关书籍
            </p>
          </div>
        </li>
      </ul>
    </div>
  </div>


  <div class="layui-form-item layui-hide">
    <button class="layui-btn" lay-submit lay-filter="LAY-user-role-submit" id="LAY-user-role-submit">提交</button>
  </div>
</div>


<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
  layui.config({
    base: '/static/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form'], function(){
    var $ = layui.$
            ,admin = layui.admin
            ,form = layui.form;


    /* 自定义验证规则 */
    form.verify({
      title: function(value){
        if(value.length > 16){
          return '字数过长';
        }
      }
    });
  });


  function delItem(index) {
    var className = layui.$("#item_" + index).attr('class');
    if (className.indexOf('defult') !== -1) {
      layui.$("#item_" + index).css('display', 'none');
      layui.$("#input_"+index).val(0);
    } else {
      layui.$("#item_" + index).remove();
    }
  }
  
  function addItem() {
    var length = document.getElementsByClassName("recommend").length;
    var html = "<div class=\"layui-form-item recommend\" id=\"item_"+length+"\">\n" +
            "  <label class=\"layui-form-label\"></label>\n" +
            "  <div class=\"layui-input-inline\" style=\"width: 150px !important;\">\n" +
            "    <input type=\"text\" name=\"title["+length+"]\" lay-verify=\"required|title\" placeholder=\"请输入推荐位标题\" autocomplete=\"off\" class=\"layui-input\" value=\"\">\n" +
            "  </div>\n" +
            "\n" +
            "  <div class=\"layui-input-inline\" style=\"width: 250px !important;\">\n" +
            "    <input type=\"radio\" name=\"freq["+length+"]\"  value=\"0\" title=\"无区分\">\n" +
            "    <input type=\"radio\" name=\"freq["+length+"]\"  value=\"1\" title=\"男频\">\n" +
            "    <input type=\"radio\" name=\"freq["+length+"]\"  value=\"2\" title=\"女频\">\n" +
            "  </div>\n" +
            "\n" +
            "\n" +
            "  <div class=\"layui-btn-group\">\n" +
            "    <button type=\"button\" class=\"layui-btn layui-btn-primary layui-btn-xs\" style=\"margin-top: 8px;\" onclick=\"delItem('" + length + "');\">\n" +
            "      <i class=\"layui-icon\">&#xe640;</i>\n" +
            "    </button>\n" +
            "  </div>\n" +
            "</div>";
    layui.$("#addButton").before(html);
    layui.form.render();
  }

  function showDefult() {
    layui.$(".defult").css('display','block');

    {foreach $template as $k => $v}
    layui.$("#input_{$k}").val(1);
    {/foreach}
  }
</script>
</body>
</html>
